package com.locator.view;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;
import com.locator.R;

public class CallLocatorItemizedOverlay extends ItemizedOverlay<OverlayItem> {
	private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
	private Context mContext;
	
	
	public CallLocatorItemizedOverlay(Drawable defaultMarker) {
		  super(boundCenterBottom(defaultMarker));
	}
	
	public CallLocatorItemizedOverlay(Drawable defaultMarker, Context context) {
		  super(boundCenterBottom(defaultMarker));
		  mContext = context;
	}
	
	@Override
	protected OverlayItem createItem(int i) {
	  return mOverlays.get(i);
	}
	
	@Override
	public int size() {
	  return mOverlays.size();
	}
	
	@Override
	protected boolean onTap(int index) {
	  OverlayItem item = mOverlays.get(index);
	  Dialog dialog = new Dialog(mContext);
	  //AlertDialog.Builder dialog = new AlertDialog.Builder(mContext); 
	  dialog.setContentView(R.layout.custom_dialog);
	  System.out.println(item.getTitle());
	  dialog.setTitle(item.getTitle());
	  
	  TextView text = (TextView) dialog.findViewById(R.id.dialogtext);
	  text.setText(item.getSnippet());
	  
	  ImageView img = (ImageView) dialog.findViewById(R.id.dialogcallicon);
	  img.setImageResource(R.drawable.map_pointer);
	  
	  dialog.show();
	  return true;
	}
	
	public void addOverlay(OverlayItem overlay) {
	    mOverlays.add(overlay);
	    populate();
	}
}
